<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:cal="http://www.codeplex.com/CompositeWPF"
                    xmlns:Extensibility="clr-namespace:ScrumSprintMonitor.Extensibility;assembly=ScrumSprintMonitor.Extensibility"
                    xmlns:converters="clr-namespace:ScrumSprintMonitor.UI.Wpf.Converters;assembly=ScrumSprintMonitor.UI.Wpf"
                    xmlns:ViewModels="clr-namespace:ScrumSprintMonitor.Modules.WorkItemMonitor.ViewModels"
                    xmlns:Behaviors="clr-namespace:ScrumSprintMonitor.UI.Wpf.Behaviors;assembly=ScrumSprintMonitor.UI.Wpf">

	<converters:DateTimeValueConverter x:Key="DateTimeValueConverter" />

	<DataTemplate x:Key="ExceptionDataTemplate">
		<TextBlock Foreground="White" TextWrapping="Wrap" FontSize="56pt" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding ExceptionMessage}" />
	</DataTemplate>

	<DataTemplate x:Key="WorkItemNotEstimatedErrorDataTemplate">
		<TextBlock Foreground="White" TextWrapping="Wrap" FontSize="56pt" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding StringFormat=Backlog item #\{0\} contains no estimates for remaining work., Path=Exception.WorkItem.Id}" />
	</DataTemplate>

	<DataTemplate x:Key="ErrorDataTemplate">
		<Grid>
			<Grid.RowDefinitions>
				<RowDefinition Height="*" />
				<RowDefinition Height="Auto" />
			</Grid.RowDefinitions>

			<ContentPresenter Grid.Row="0" Content="{Binding}" ContentTemplate="{StaticResource ExceptionDataTemplate}" Focusable="False" />

			<TextBlock Margin="5" Grid.Row="1" Text="{Binding Path=DeploymentVersion, StringFormat='Version: {0}'}" HorizontalAlignment="Center" Foreground="#7FFFFFFF" />
		</Grid>
	</DataTemplate>

	<DataTemplate x:Key="OnlineDataTemplate">
		<Grid>
			<!-- Background -->
			<ContentControl cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.PrimaryMonitorBackgroundRegion}" Focusable="False" />

			<DockPanel LastChildFill="True">
				<StackPanel DockPanel.Dock="Bottom" Margin="5">
					<!--<ItemsControl Grid.Column="0" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.PrimaryMonitorBottomDockRegion}" Focusable="False" />-->

					<!--Bottom line with build status, app version and last update time-->
					<Grid Margin="0,5,0,0" VerticalAlignment="Bottom">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="*" />
							<ColumnDefinition Width="Auto" />
						</Grid.ColumnDefinitions>

						<ContentControl Grid.Column="0" VerticalAlignment="Bottom" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.BuildStatusDetailsRegion}" Focusable="False" />

						<TextBlock Grid.Column="1" VerticalAlignment="Bottom" Text="{Binding Path=DeploymentVersion, StringFormat='Version: {0}'}" HorizontalAlignment="Center" Foreground="#7FFFFFFF" />

						<Grid Grid.Column="2" VerticalAlignment="Bottom">
							<Grid.ColumnDefinitions>
								<ColumnDefinition />
								<ColumnDefinition />
							</Grid.ColumnDefinitions>

							<Grid Grid.Column="1" x:Name="LastRefreshArea">
								<Grid.ColumnDefinitions>
									<ColumnDefinition />
									<ColumnDefinition Width="4" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<Grid.RowDefinitions>
									<RowDefinition />
									<RowDefinition />
								</Grid.RowDefinitions>

								<TextBlock Grid.Column="0" Text="Last update:" HorizontalAlignment="Right" Foreground="#7FFFFFFF" Opacity="0.5" />
								<TextBlock Grid.Column="2" Text="{Binding Path=LastUpdate, Converter={StaticResource DateTimeValueConverter}, ConverterParameter=G}" Foreground="#7FFFFFFF" />
								<StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal">
									<Image Source="..\Resources\VistaICO\Refresh.png" Stretch="Uniform" Height="16" />

									<TextBlock Margin="3,0,0,0" Text="Last refresh:" HorizontalAlignment="Right" Foreground="#7FFFFFFF" Opacity="0.5" />
								</StackPanel>
								<TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding Path=LastRefresh, Converter={StaticResource DateTimeValueConverter}, ConverterParameter=G}" Foreground="#7FFFFFFF" />
							</Grid>

							<Button Grid.Column="0" Grid.ColumnSpan="2" Command="{Binding RefreshCommand}" Opacity="0.001" Grid.ZIndex="100">
								<Button.Triggers>
									<EventTrigger RoutedEvent="Button.MouseEnter">
										<BeginStoryboard>
											<Storyboard>
												<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)">
													<EasingDoubleKeyFrame KeyTime="00:00:00.2" Value="1">
														<EasingDoubleKeyFrame.EasingFunction>
															<CubicEase EasingMode="EaseInOut" />
														</EasingDoubleKeyFrame.EasingFunction>
													</EasingDoubleKeyFrame>
												</DoubleAnimationUsingKeyFrames>
											</Storyboard>
										</BeginStoryboard>
									</EventTrigger>
									<EventTrigger RoutedEvent="Button.MouseLeave">
										<BeginStoryboard>
											<Storyboard>
												<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)">
													<EasingDoubleKeyFrame KeyTime="00:00:01" Value="0.001">
														<EasingDoubleKeyFrame.EasingFunction>
															<CubicEase EasingMode="EaseInOut" />
														</EasingDoubleKeyFrame.EasingFunction>
													</EasingDoubleKeyFrame>
												</DoubleAnimationUsingKeyFrames>
											</Storyboard>
										</BeginStoryboard>
									</EventTrigger>
								</Button.Triggers>

								<Viewbox Margin="6">
									<Grid>
										<Grid.ColumnDefinitions>
											<ColumnDefinition />
											<ColumnDefinition />
										</Grid.ColumnDefinitions>

										<Image Grid.Column="0" Margin="6" Source="..\Resources\VistaICO\Refresh.png" Stretch="Uniform" Height="32" />
										<TextBlock Grid.Column="1" Margin="6" VerticalAlignment="Center" Text="Refresh!" />
									</Grid>
								</Viewbox>
							</Button>
						</Grid>
					</Grid>
				</StackPanel>

				<Grid DockPanel.Dock="Top">
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="Auto" />
						<ColumnDefinition Width="*" />
						<ColumnDefinition Width="Auto" />
					</Grid.ColumnDefinitions>

					<!-- Left column -->
					<ItemsControl Grid.Column="0" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.PrimaryMonitorLeftDockRegion}" Focusable="False">
						<ItemsControl.ItemsPanel>
							<ItemsPanelTemplate>
								<StackPanel Orientation="Horizontal" />
							</ItemsPanelTemplate>
						</ItemsControl.ItemsPanel>
					</ItemsControl>

					<!-- Sprint Overview Region -->
					<Grid Grid.Column="1" x:Name="SprintOverviewRegion" Margin="20">
						<Grid.ColumnDefinitions>
							<ColumnDefinition>
								<ColumnDefinition.Style>
									<Style TargetType="{x:Type ColumnDefinition}">
										<Setter Property="Width" Value="0" />

										<Style.Triggers>
											<DataTrigger Binding="{Binding SprintTitleOrientation}" Value="Vertical">
												<Setter Property="Width" Value="1*" />
											</DataTrigger>
										</Style.Triggers>
									</Style>
								</ColumnDefinition.Style>
							</ColumnDefinition>
							<ColumnDefinition Width="7*" />
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition>
								<RowDefinition.Style>
									<Style TargetType="{x:Type RowDefinition}">
										<Setter Property="Height" Value="0" />

										<Style.Triggers>
											<DataTrigger Binding="{Binding SprintTitleOrientation}" Value="Horizontal">
												<Setter Property="Height" Value="2*" />
											</DataTrigger>
										</Style.Triggers>
									</Style>
								</RowDefinition.Style>
							</RowDefinition>
							<RowDefinition>
								<RowDefinition.Style>
									<Style TargetType="{x:Type RowDefinition}">
										<Setter Property="Height" Value="5*" />

										<Style.Triggers>
											<DataTrigger Binding="{Binding SprintMode}" Value="Planning">
												<Setter Property="Height" Value="Auto" />
											</DataTrigger>
										</Style.Triggers>
									</Style>
								</RowDefinition.Style>
							</RowDefinition>
							<RowDefinition Height="2*" />
							<RowDefinition Height="2*" />
							<RowDefinition Height="Auto" />
						</Grid.RowDefinitions>

						<!-- Horizontal sprint title region -->
						<ItemsControl Grid.Row="0" Grid.ColumnSpan="2" x:Name="HorizontalSprintTitleRegion" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.HorizontalSprintTitleRegion}" Focusable="False">
							<ItemsControl.ItemsPanel>
								<ItemsPanelTemplate>
									<Grid />
								</ItemsPanelTemplate>
							</ItemsControl.ItemsPanel>
						</ItemsControl>

						<!-- Vertical sprint title region -->
						<ItemsControl Grid.Row="0" Grid.RowSpan="5" x:Name="VerticalSprintTitleRegion" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.VerticalSprintTitleRegion}" Focusable="False">
							<ItemsControl.ItemsPanel>
								<ItemsPanelTemplate>
									<Grid />
								</ItemsPanelTemplate>
							</ItemsControl.ItemsPanel>
						</ItemsControl>

						<!--Sprint Overview Charts-->
						<ItemsControl Grid.Row="1" Grid.Column="1" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.SprintOverviewChartsRegion}" Focusable="False">
							<ItemsControl.ItemsPanel>
								<ItemsPanelTemplate>
									<UniformGrid Rows="1" IsItemsHost="True" HorizontalAlignment="Stretch" />
								</ItemsPanelTemplate>
							</ItemsControl.ItemsPanel>
						</ItemsControl>

						<!--Sprint Burndown Chart-->
						<ItemsControl Grid.Row="2" Grid.Column="1" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.SprintBurndownChartRegion}" Focusable="False">
							<ItemsControl.ItemsPanel>
								<ItemsPanelTemplate>
									<Grid />
								</ItemsPanelTemplate>
							</ItemsControl.ItemsPanel>
						</ItemsControl>

						<!--Sprint Statistics-->
						<Viewbox Grid.Row="3" Grid.Column="1">
							<ItemsControl cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.SprintStatisticsRegion}" Focusable="False">
								<ItemsControl.ItemsPanel>
									<ItemsPanelTemplate>
										<StackPanel Grid.IsSharedSizeScope="True" />
									</ItemsPanelTemplate>
								</ItemsControl.ItemsPanel>
							</ItemsControl>
						</Viewbox>

						<!--Bottom Dock Region-->
						<ItemsControl Grid.Row="4" Grid.Column="1" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.PrimaryMonitorBottomDockRegion}" Focusable="False" />
					</Grid>

					<!-- Right column -->
					<ItemsControl Grid.Column="2" cal:RegionManager.RegionName="{x:Static Extensibility:RegionNames.PrimaryMonitorRightDockRegion}" Focusable="False">
						<ItemsControl.ItemsPanel>
							<ItemsPanelTemplate>
								<StackPanel Orientation="Horizontal" />
							</ItemsPanelTemplate>
						</ItemsControl.ItemsPanel>
					</ItemsControl>
				</Grid>
			</DockPanel>
		</Grid>
	</DataTemplate>

	<DataTemplate DataType="{x:Type ViewModels:MonitorViewModel}">
		<Grid Behaviors:BusyIndicatorBehavior.BusyState="{Binding ShowProgress}"
		      Behaviors:BusyIndicatorBehavior.AddMargins="True">
			<ContentPresenter Content="{Binding}" Focusable="False">
				<ContentPresenter.Style>
					<Style TargetType="{x:Type ContentPresenter}">
						<Setter Property="ContentTemplate">
							<Setter.Value>
								<DataTemplate />
							</Setter.Value>
						</Setter>

						<Style.Triggers>
							<DataTrigger Binding="{Binding Path=ActiveView}" Value="SprintView">
								<Setter Property="ContentTemplate" Value="{StaticResource OnlineDataTemplate}" />
							</DataTrigger>

							<DataTrigger Binding="{Binding Path=ActiveView}" Value="ExceptionView">
								<Setter Property="ContentTemplate" Value="{StaticResource ErrorDataTemplate}" />
							</DataTrigger>

							<DataTrigger Binding="{Binding Path=ActiveView}" Value="FoundUnassignedWorkItems">
								<Setter Property="ContentTemplate" Value="{StaticResource WorkItemNotEstimatedErrorDataTemplate}" />
							</DataTrigger>
						</Style.Triggers>
					</Style>
				</ContentPresenter.Style>
			</ContentPresenter>
		</Grid>
	</DataTemplate>
</ResourceDictionary>